# -*- coding: utf-8 -*-
import openai
import os

openai.api_key = "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"
openai.api_base = "https://openai.naraka.top/v1"

prompt = '请以JSON格式输出一部修仙类型小说的前10章提纲,要求如下:\
- 小说类型:修仙,豪门世家,强强CP \
- 故事梗概:女主在都市打工,意外发现一个修仙的世界,通过自己的聪明才智在修仙界逐步晋升,最终成为无敌仙尊。 \
- 输出格式:JSON数组,每个元素是一个包含"title"和"summary"两个字段的对象,分别表示该章节的标题和简介\
- 完整小说总章节数量:2000章\
- 要求输出章节数量:10章\
- 示例格式:\
[\
  {\
    "title": "第一章 xxx",\
    "summary": "描述xxx"  \
  },\
  {\
    "title": "第二章 xxx",\
    "summary": "描述xxx"\
  } \
]'
# prompt = '今天是星期一，明天是星期三，这样是对的吗？'
# gpt-3.5-turbo-16k, text-davinci-003
model = "gpt-3.5-turbo-0613"


# 创建一个 GPT-3 请求
# completion = chatgpt.ChatCompletion.create(
#     model=model,
#     messages=[
#         {"role": "user", "content": content}
#     ]
# )
# print(completion.choices[0].message.get("content", ''))

def generate_text(prompt, model=model):
    messages = [
        {"role": "user", "content": prompt}
    ]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0.3,
    )

    texts = response.choices[0].message.get("content", '')
    return texts


text = generate_text(prompt)

print(text)
# 生成图片
# response = chatgpt.Image.create(
#   prompt="A fluffy white cat with blue eyes sitting in a basket of flowers, looking up adorably at the camera",
#   n=1,
#   size="1024x1024"
# )
# image_url = response['data'][0]['url']
# print(image_url)
